package com.syg.listener2;

import com.syg.event.MyEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * 方式2 将监听器装载入spring容器
 * 只需要加@Component注解即可
 */
@Component
public class MyListener2 implements ApplicationListener<MyEvent> {
    Logger log = LoggerFactory.getLogger(MyListener2.class);

    @Override
    public void onApplicationEvent(MyEvent event) {
        log.info(String.format("%s监听到事件源：%s.", MyListener2.class.getName(), event.getSource()));
    }
}
